package Model;

import javax.swing.event.EventListenerList;
import Controler.VolumeListener;


public class TrainAterrissage {
	
	public enum Etat{
		FERME,//Haut
		TRANSITIONUP,TRANSITIONDOWN,
		OUVERT//Bas
	}

	private Etat etat;
	private EventListenerList listeners;
	
	public TrainAterrissage(){
		this.etat=Etat.FERME;
		
		listeners = new EventListenerList();
	}
	
	long counter=0;
	
	public void switcher(){
		
		switch(this.etat){
			case FERME:
				this.etat=Etat.TRANSITIONDOWN;
				break;
			case OUVERT:
				this.etat=Etat.TRANSITIONUP;
			break;
			case TRANSITIONDOWN:
				this.etat=Etat.TRANSITIONUP;
			break;
			case TRANSITIONUP:
				this.etat=Etat.TRANSITIONDOWN;
			break;
		}
		
		fireVolumeChanged();
	}
	public void finish(){
		if(this.etat==Etat.TRANSITIONDOWN){
			this.etat=Etat.OUVERT;
		}
		if(this.etat==Etat.TRANSITIONUP){
			this.etat=Etat.FERME;
		}
	}
	public boolean ouvert(){

		System.out.println(this.etat);
		if(this.etat==Etat.OUVERT){
			return true;
		}
		else{
			return false;
		}
	}
	public Etat getEtat() {
		return this.etat;
	}
	
	/*
	 * Pour les listeners
	 */
	
	public void addVolumeListener(VolumeListener listener){
		listeners.add(VolumeListener.class, listener);
	}
 
	public void removeVolumeListener(VolumeListener l){
		 listeners.remove(VolumeListener.class, l);
	}
 
	public void fireVolumeChanged(){
		VolumeListener[] listenerList = (VolumeListener[])listeners.getListeners(VolumeListener.class);
 
		for(VolumeListener listener : listenerList){
			listener.volumeChanged(new VolumeChangedEvent(this, getVolume()));
		}
	}
}
